package com.yulebaby.callsenter.adapter;


import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yulebaby.callsenter.R;
import com.yulebaby.callsenter.bean.CallLogBean;
import com.yulebaby.callsenter.global.App;
import com.yulebaby.callsenter.utils.DateUtil;
import com.yulebaby.callsenter.utils.ImageLoader;

import java.util.List;

/**
 * @author zhangbo
 * @date 2017-1-12.
 */

public class SelectRecordAdapter extends BaseQuickAdapter<CallLogBean, BaseViewHolder> {

    public SelectRecordAdapter(List<CallLogBean> list) {
        super(R.layout.item_return_record, list);
    }


    @Override
    protected void convert(BaseViewHolder baseViewHolder, CallLogBean callLogBean) {
        baseViewHolder.setText(R.id.tv_phonenum, callLogBean.getCustomer_phone())
                .setText(R.id.tv_date, DateUtil.formatDateTimeDetail(callLogBean.getCall_time()))
                .setText(R.id.tv_calltime, DateUtil.timeChange(callLogBean.getCall_duration()).equals("0分0秒") ? "未接通" : DateUtil.timeChange(callLogBean.getCall_duration()))
                .setText(R.id.tv_phonename, callLogBean.getCustomer_name())
                .addOnClickListener(R.id.iv_play)
                .addOnClickListener(R.id.iv_state);
        switch (callLogBean.getPlayState()) {
            case 0:
                ImageLoader.load(App.mContext, R.drawable.phone_fail, baseViewHolder.getView(R.id.iv_play));
                break;
            case 1:
                ImageLoader.load(App.mContext, R.drawable.phone_pause, baseViewHolder.getView(R.id.iv_play));
                break;
            case 2:
                ImageLoader.load(App.mContext, R.drawable.phone_success, baseViewHolder.getView(R.id.iv_play));
                break;
        }
        //通话类型，1 来电 .INCOMING_TYPE；2 已拨 .OUTGOING_；3 未接 .MISSED_
        switch (callLogBean.getCall_type()) {
            case 1:
                baseViewHolder.setText(R.id.tv_type, "呼入");
                break;
            case 2:
                baseViewHolder.setText(R.id.tv_type, "呼出");
                break;
            case 3:
                baseViewHolder.setText(R.id.tv_type, "未接通");
                break;
        }

        ImageView view = baseViewHolder.getView(R.id.iv_state);
        switch (callLogBean.getSelectedState()) {
            case 0:
                view.setClickable(true);
                ImageLoader.load(App.mContext, R.drawable.record_unselect, view);

                break;
            case 1:
                view.setClickable(true);
                ImageLoader.load(App.mContext, R.drawable.record_selected, view);
                break;
            case 2:
                view.setClickable(false);
                ImageLoader.load(App.mContext, R.drawable.record_preselected, view);
                break;
        }
    }

}
